<template>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 15px;margin-top: 15px; background-color: #f5f6fa">
      <el-breadcrumb-item
          v-for="(item,index) in breadList"
          :key="index"
          :to="{ path: item.path }"
      >{{ item.meta.title }} </el-breadcrumb-item>

    </el-breadcrumb>
</template>

<script>
export default {
  name:'Breadcrumb',
  data() {
    return {
      breadList: [] // 路由集合
    };
  },
  watch: {
    $route() {
      this.getBreadcrumb();
    }
  },
  methods: {
    isHome(route) {
      return route.name === "home";
    },
    getBreadcrumb() {
      let matched = this.$route.matched;
      //如果不是首页
      if (!this.isHome(matched[0])) {
        matched = [].concat(matched);
      }
      this.breadList = matched;
    },
    pt() {
      console.log(this.breadList)
    }
  },
  created() {
    this.getBreadcrumb();
    this.pt()
  }
};
</script>
